package edu.dgut.bbssystem.controller;


import edu.dgut.bbssystem.common.ActionResult;
import edu.dgut.bbssystem.common.Constant;
import edu.dgut.bbssystem.pojo.Message;
import edu.dgut.bbssystem.service.MessageService;
import edu.dgut.bbssystem.util.BbsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;


@RestController
@RequestMapping("/message")
//@CrossOrigin
public class MessageController {
    @Autowired
    private MessageService messageService;

    @PostMapping("/addMessage")
    public ActionResult addMessage(Message message){
        ActionResult actionResult = new ActionResult();
        int add = messageService.add(message);
        actionResult.setCode(add);
        return actionResult;
    }
    @GetMapping("/newMessageCount")
    public ActionResult newMessageCount(HttpSession session){
        int userId = BbsUtils.getUserInSession(session).getUserId();
        int count = messageService.newMessageCount(userId);
        return new ActionResult(Constant.SUCCESS,count);
    }
    @GetMapping("/messageVo")
    public ActionResult messageVo(HttpSession session){
        int userId = BbsUtils.getUserInSession(session).getUserId();
        int count = messageService.getMessageVo(userId);
        return new ActionResult(Constant.SUCCESS,count);
    }
/*    @GetMapping("/pageMessage")
    public ActionResult pageMessage(HttpSession session,int pageNum, int pageSize){
        int userId = BbsUtils.getUserInSession(session).getUserId();
        PageInfo<User> userPageInfo =  messageService.pageQueryAllByReceiver(pageNum, pageSize,userId);
       return new ActionResult(Constant.SUCCESS,count);
    }*/
    @DeleteMapping("/deleteMessage")
    public ActionResult deleteMessage(int id){
        ActionResult actionResult = new ActionResult();
        int code = messageService.deleteMessage(id);

        return actionResult;
    }

}
